//
//  ZCInvolvedDetailsVC.m
//  zctx
//
//  Created by apple on 15/10/12.
//  Copyright © 2015年 sanliang. All rights reserved.
//


#import "ZCInvolvedDetailsVC.h"
#import "ZCRaisePayVC.h"
#import "ZCLoginVC.h"
#import "ActionView.h"
#import "AdView.h"
#import "ZCdetectiondetailsVC.h"
#import "ZCRaiseVC.h"

#import "ZCInvolvedDeatailsCell.h"
#import "ZCInvolvedmubiaoCell.h"
#import "ZCinvolvedprogressCell.h"
#import "ZCinvolvedOtherCell.h"
#import "ZCInvolvedContentCell.h"
#import "ZCInvolvedNewcommentsCell.h"
#import "ZCinvolvedIconCell.h"
#import "ZCInvolvedSupportCell.h"

#import "WyzAlbumViewController.h" //广告图片浏览
#import "HcCustomKeyboard.h"  //键盘
#import "ZCCommentVC.h" //评论列表
#import "ZCSponsorVC.h" //支持者列表
#import "ZCCommentDetailsVC.h"  //评论详情
#import "payShareView.h"    //分享控件

#import "ZCHeadView.h"
#import "ZCInvolvedDetailsModelThumbList.h"

#import "iToastImage.h"
#import "ZCMeRaiseVC.h" //我的项目
#import "ZCRaiseCell.h"

#import "ZCInvolvedToolView.h"
#import "UIView+WHC_AutoLayout.h"

@interface ZCInvolvedDetailsVC ()<ZCInvolvedContentCellDelegate,ZCinvolvedOtherCellDelegate,HcCustomKeyboardDelegate,ZCInvolvedNewcommentsCellDelegate>
@property (nonatomic,strong)AdView *adView;
@property BOOL iszhan;
@property (nonatomic,strong)NSMutableArray *imagesURL;
@property (nonatomic,strong)UIButton *zhichibutton;
@property (nonatomic,strong)ZCInvolvedToolView * toolView;
@property BOOL iscomment;
@end

@implementation ZCInvolvedDetailsVC


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"ZCInvolvedDetailsVC"];
    [MTA trackPageViewBegin:@"ZCInvolvedDetailsVC"];
    self.tabBarController.hidesBottomBarWhenPushed = YES;
    
//    if (self.backState  ==1 ||self.backState == 2) {
//        
//    }
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"ZCInvolvedDetailsVC"];
    [MTA trackPageViewEnd:@"ZCInvolvedDetailsVC"];
}
-(void)updateRequest{
    if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus >0) {
        self.bannerView.hidden = YES;
    }
    [self requestProjectdetailsdata];
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
//    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.navigationItem.title = @"检测项目详情";
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(PayMoneysuccess) name:@"payMoney" object:nil];

    self.view.backgroundColor = [UIColor whiteColor];
    self.iszhan = NO;
    self.iscomment = YES;//开始点击评论
    NSLog(@"pid = %@",self.pid);
    sponsorArray = [NSMutableArray arrayWithCapacity:0];

    self.imagesURL = [NSMutableArray array];
    [self initnavegation]; //导航栏

    
    [self initTableView];
    [self requestProjectdetailsdata];//请求项目详情数据
    
    [self.tableView registerNib:[UINib nibWithNibName:@"ZCInvolvedmubiaoCell" bundle:nil] forCellReuseIdentifier:@"biaocell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"ZCInvolvedDeatailsCell" bundle:nil] forCellReuseIdentifier:@"involveddetailCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"ZCinvolvedprogressCell" bundle:nil] forCellReuseIdentifier:@"progressCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"ZCInvolvedContentCell" bundle:nil] forCellReuseIdentifier:@"contentCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"ZCProjectdetailsSponsorCell" bundle:nil] forCellReuseIdentifier:@"sponsorcell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"ZCInvolvedcommentsCell" bundle:nil] forCellReuseIdentifier:@"commemtsCell"];
    
    [self.tableView registerClass:[ZCInvolvedNewcommentsCell class]
             forCellReuseIdentifier:@"commemtasdhhfsCell"];
    
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)])
    {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
    {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}

-(void)PayMoneysuccess{
    [self gotodeans];
    [self showShareView];
}

#pragma mark 导航栏
-(void)initnavegation{
    
    UIButton * leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(0, 0, 19, 36);
    [leftButton setImage:[UIImage imageNamed:@"navigation_back"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(backButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * barButtonItem_leftNavBar = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = barButtonItem_leftNavBar;

    
    rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    rightButton.frame = CGRectMake(0, 0, 24, 22);
    [rightButton addTarget:self action:@selector(shareButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * barButtonItem_rightNavBar = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    
    [rightButton setImage:[UIImage imageNamed:@"Involved_tshare"] forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = barButtonItem_rightNavBar;

}

#pragma mark FooterView
-(void)initFooterView{
    
    NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"ZCInvolvedToolView" owner:self options:nil];
    //得到第一个UIView
    self.toolView = [nib objectAtIndex:0];
    [self.view addSubview:self.toolView];
//    self.toolView.hidden = YES;
    [self.toolView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.centerX);
        make.height.mas_equalTo(44);
        make.width.mas_equalTo(@(SCREEN_WIDTH));
        make.top.equalTo(self.tableView.bottom).with.offset(0);
    }];
    self.toolView.involvedModel = datadictionary;
    
    __weak ZCInvolvedDetailsVC *weakSelf = self;
    self.toolView.TshareBlock = ^(void){
        [weakSelf shareButtonPressed];
    };
    self.toolView.TcollectBlock = ^(void){
        [weakSelf collectionButtonPressed];
    };
    self.toolView.TcommentBlock = ^(void){
        NSIndexPath *scrollIndexPath;
        if(weakSelf.iscomment ==YES){
            scrollIndexPath = [NSIndexPath indexPathForRow:0 inSection:2];
            [weakSelf.tableView scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
        }else{
            [weakSelf.tableView setContentOffset:CGPointMake(0,-64) animated:YES];
        }
        weakSelf.iscomment = !weakSelf.iscomment;
    };
    self.toolView.TtextfiledBlock = ^(void){
        [weakSelf ClickCommentButtonconnect];
    };

}

-(void)backButtonPressed{
    if (self.backState == 1) {
        theAppdelegate.tbc.selectedIndex = 0;
        [self.navigationController popToRootViewControllerAnimated:YES];
    }else if(self.backState ==2){
        [self.navigationController popToRootViewControllerAnimated:YES];
    }else{
        [self.navigationController popViewControllerAnimated:YES];
    }
}

#pragma mark 请求项目详情数据
-(void)requestProjectdetailsdata{
    
    NSLog(@"ssspid = %@",_pid);
    [GMDCircleLoader setOnView:self.view withTitle:@"努力加载中..." animated:YES];
    [NetworkManager requestFoundingGetOneWithId:_pid Mid:UserModel.mid password:UserModel.password success:^(NSDictionary *dictResponse) {
        [GMDCircleLoader hideFromView:self.view animated:YES];
        datadictionary = [ZCInvolvedDetailsModelContent modelObjectWithDictionary:dictResponse];
        [self initFooterView];
        if (![datadictionary.result isEqualToString:@"0"]) {
            [self.zhichibutton setTitle:@"我要检测" forState:UIControlStateNormal];
        }else{
            if ([datadictionary.state isEqualToString:@"2"]) {
                [self.zhichibutton setTitle:@"立即支持" forState:UIControlStateNormal];
            }
        }
        [self initTableViewHeaderView];
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        [GMDCircleLoader hideFromView:self.view animated:YES];
        self.bannerView.hidden = NO;
    }];
}

#pragma mark 请求支持者数据
-(void)requestSupporterdata{
//    NSLog(@"pid = %@",self.pid);
    [GMDCircleLoader setOnView:self.view withTitle:@"努力加载中..." animated:YES];
    [NetworkManager requestFoundingGetOneSponsorWithId:self.pid Mid:UserModel.mid password:UserModel.password pagecount:@"0" success:^(NSDictionary *dictResponse) {
        [GMDCircleLoader hideFromView:self.view animated:YES];
    
        if ([[dictResponse objectForKey:@"content"] isKindOfClass:[NSArray class]]){
            NSArray *array = (NSArray *)[dictResponse objectForKey:@"content"];
            NSLog(@"sdf");
            if (array.count>0) {
                sponsorArray = [array mutableCopy];
                
                dispatch_async(dispatch_get_main_queue(),^(void){
                   [self.tableView reloadData];
                });
            }
        }
    } failure:^(NSError *error) {
        [GMDCircleLoader hideFromView:self.view animated:YES];
    }];
}

#pragma mark TableViewHeaderView

-(void)initTableViewHeaderView{
    UIView *headView = [[UIView alloc]initWithFrame:CGRectZero];
    if ([datadictionary.result isEqualToString:@"0"]) {
        
        headView.frame =  CGRectMake(0, 0, SCREEN_WIDTH,216 +62 +80);
        ZCInvolvedSupportCell *cell = [[[NSBundle mainBundle]loadNibNamed:@"ZCInvolvedSupportCell" owner:self options:nil]firstObject];
        [cell.suportBtn addTarget:self action:@selector(submitButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [headView addSubview:cell.contentView];
        cell.contentView.frame = CGRectMake(0, 216, SCREEN_WIDTH, 80);
        ZCHeadView *hedView = [[ZCHeadView alloc]initWithFrame:CGRectMake(0, 216 +80, SCREEN_WIDTH, 62) andModel: datadictionary];
        [headView addSubview:hedView];
     
    }else{
        headView.frame =  CGRectMake(0, 0, SCREEN_WIDTH,216 +62);
        ZCHeadView *hedView = [[ZCHeadView alloc]initWithFrame:CGRectMake(0, 216, SCREEN_WIDTH, 62) andModel: datadictionary];
        [headView addSubview:hedView];
    }
    headView.backgroundColor = [UIColor whiteColor];
    
    for (ZCInvolvedDetailsModelThumbList *imageDic in datadictionary.thumbList) {
        NSString *urlstr = [NSString stringWithFormat:@"%@%@",[NetworkManager strURLBasic],imageDic.imgUrl];
        [self.imagesURL addObject:urlstr];
    }
    self.adView = [AdView adScrollViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 216)  \
                              imageLinkURL:self.imagesURL\
                       placeHoderImageName:@"placehold_involvedDetail" \
                      pageControlShowStyle:UIPageControlShowStyleCenter];
    
    NSArray *titles = @[datadictionary.pjname];
    __block  ZCInvolvedDetailsVC *weakself = self;
    [self.adView setAdTitleArray:titles withShowStyle:AdTitleShowStyleLeft];
    self.adView.adMoveTime = 2.0;
    //图片被点击后回调的方法
    self.adView.callBack = ^(NSInteger index,NSString * imageURL)
    {
        [weakself showPhotoBrowser:0];
    };
    [headView addSubview:self.adView];
    

    UIImageView *resultImgView = [[UIImageView alloc]init];
    [headView addSubview:resultImgView];
    [resultImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(headView.right).with.offset(-18);
        make.bottom.equalTo(headView.bottom).with.offset(0);
        make.height.mas_equalTo(87);
        make.width.mas_equalTo(95);
    }];
    if ([datadictionary.result isEqualToString:@"1"]) {
        resultImgView.image = [UIImage imageNamed:@"projectdetail_good_yes"];
    }else if ([datadictionary.result isEqualToString:@"2"]){
        resultImgView.image = [UIImage imageNamed:@"projectdetail_good_no"];
    }else{
        resultImgView.hidden = YES;
    }
    self.tableView.tableHeaderView = headView;
}

-(void)initTableView{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    [self.view addSubview:self.tableView];
    [self.tableView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(0, 0, 44, 0));
    }];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.sectionFooterHeight = 0.0001;
    self.tableView.backgroundColor = [UIColor colorWithHexString:@"#fafcfb"];
    self.tableView.separatorColor = RGB(236, 237, 238);
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if (datadictionary) {
        return 3;
    }else{
        return 0;
    }
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0) {
        if ([self.stateid isEqualToString:@"0"]) {
            return 6;
        }else{
            return 5;
        }
    }else if(section==1){
        return 1+datadictionary.hotSponsors.count;
    }else{
        NSLog(@"111111------- =%ld",1+datadictionary.hotComments.count);
        return 1+datadictionary.hotComments.count;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0){
        return [self sectionOneTableView:tableView cellFortIndexPath:indexPath];
    }
    else if(indexPath.section==1){//支持者
        return [self sectionSponsorTableView:tableView cellFortIndexPath:indexPath];
    }else{ //评论信息
        if (indexPath.row==0) {
            static NSString *IDcell = @"goodcommentCell";
            ZCinvolvedOtherCell *cell = [tableView dequeueReusableCellWithIdentifier:IDcell];
            if (!cell) {
                cell = [[ZCinvolvedOtherCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:IDcell cellType:ZCinvolvedOtherCellTypetitle];
            }
            cell.delegate = self;
            cell.labelTitle.text = @"精彩评论";
            return cell;
        }else{
            static NSString *IDcell = @"commemtasdhhfsCell";
            ZCInvolvedNewcommentsCell *cell = [tableView dequeueReusableCellWithIdentifier:IDcell];
            if (!cell) {
                cell = [[ZCInvolvedNewcommentsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:IDcell];
            }
            cell.delegate = self;
            cell.indexPath = indexPath;
            cell.friendModel = datadictionary.hotComments[indexPath.row-1];
            cell.tableView = tableView;
            return cell;
        }
    }
}


#pragma mark 第0组
-(UITableViewCell *)sectionOneTableView:(UITableView *)tableView cellFortIndexPath:(NSIndexPath *)indexPath{
    if ([self.stateid isEqualToString:@"0"]) {
        if(indexPath.row==0){
            ZCInvolvedmubiaoCell *cell = [ZCInvolvedmubiaoCell  cellWithInvolvedmubiaoCell:tableView];
            cell.detailModel = datadictionary;
            return cell;
        }else if(indexPath.row==1){
            ZCRaiseCell*cell = [[ZCRaiseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell" cellType:RaiseCellTypePrompt];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
        else if(indexPath.row==2){
            ZCinvolvedprogressCell *cell = [ZCinvolvedprogressCell cellWithinvolvedprogressCell:tableView];
            cell.model = datadictionary;
            return cell;
        }
        else if(indexPath.row==3){
            static NSString *IDcell = @"deatailCell";
            ZCinvolvedOtherCell *cell = [tableView dequeueReusableCellWithIdentifier:IDcell];
            if (!cell) {
                cell = [[ZCinvolvedOtherCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:IDcell cellType:ZCinvolvedOtherCellTypedetails];
            }
            return cell;
        }else if(indexPath.row==4){
            static NSString *IDcell = @"otherCell";
            ZCinvolvedIconCell *cell;
            cell = [[ZCinvolvedIconCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:IDcell cellType:datadictionary.latestSixSponsors];
            return cell;
        }else{
            ZCInvolvedContentCell *cell = [ZCInvolvedContentCell cellWithInvolvedContentCell:tableView];
            cell.indexPaths = indexPath;
            cell.delegate = self;
            cell.model = datadictionary;
            return cell;
        }
    }else{
        if(indexPath.row==0){
            ZCInvolvedmubiaoCell *cell = [ZCInvolvedmubiaoCell  cellWithInvolvedmubiaoCell:tableView];
            cell.detailModel = datadictionary;
            return cell;
        }else if(indexPath.row==1){
            ZCinvolvedprogressCell *cell = [ZCinvolvedprogressCell cellWithinvolvedprogressCell:tableView];
            cell.model = datadictionary;
            return cell;
        }
        else if(indexPath.row==2){
            static NSString *IDcell = @"deatailCell";
            ZCinvolvedOtherCell *cell = [tableView dequeueReusableCellWithIdentifier:IDcell];
            if (!cell) {
                cell = [[ZCinvolvedOtherCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:IDcell cellType:ZCinvolvedOtherCellTypedetails];
            }
            return cell;
        }else if(indexPath.row==3){
            static NSString *IDcell = @"otherCell";
            ZCinvolvedIconCell *cell;
            cell = [[ZCinvolvedIconCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:IDcell cellType:datadictionary.latestSixSponsors];
            return cell;
        }else{
            ZCInvolvedContentCell *cell = [ZCInvolvedContentCell cellWithInvolvedContentCell:tableView];
            cell.indexPaths = indexPath;
            cell.delegate = self;
            cell.model = datadictionary;
            return cell;
        }
    }
}


#pragma mark 支持者
-(UITableViewCell *)sectionSponsorTableView:(UITableView *)tableView cellFortIndexPath:(NSIndexPath *)indexPath{

    
    if (indexPath.row==0) {
        static NSString *IDcell = @"titleCell";
        ZCinvolvedOtherCell *cell = [tableView dequeueReusableCellWithIdentifier:IDcell];
        if (!cell) {
            cell = [[ZCinvolvedOtherCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:IDcell cellType:ZCinvolvedOtherCellTypetitle];
        }
        cell.commentButton.hidden = YES;
        cell.labelTitle.text = @"支持者";
        return cell;
        
    }else{
        ZCProjectdetailsSponsorCell *cell = [tableView dequeueReusableCellWithIdentifier:@"sponsorcell"];
        cell.Model =datadictionary.hotSponsors[indexPath.row-1];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        
        if ([self.stateid isEqualToString:@"0"]) {
            if (indexPath.row==0) {
                return 57;
            }else if (indexPath.row ==1||indexPath.row==3||indexPath.row==4){
                return 44;
            }
            else if (indexPath.row==2){
                return 66;
            }else{
                return [self tableViewIndexPath:indexPath];
            }
        }else{
            if (indexPath.row==0) {
                return 57;
            }else if (indexPath.row==2||indexPath.row==3){
                return 44;
            }else if (indexPath.row==1){
                return 66;
            }else{
                return [self tableViewIndexPath:indexPath];;
            }
        }
    }else if(indexPath.section==2){
        if (indexPath.row==0) {
            return 44;
        }else{
            return [UITableViewCell whc_CellHeightForIndexPath:indexPath tableView:tableView];
        }
    }else{
        if (indexPath.row==0) {
            return 44;
        }else{
            return 64;
        }
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footer = [[UIView alloc]init];
    if (section<1) {
        return footer;
    }else if (section==1){
        if (datadictionary.hotSponsors.count>=10) {
            NSString *sporStr = [NSString stringWithFormat:@"查看更多支持者信息(%@)>",datadictionary.sponsorsCount];
            UIButton *sporButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64)];
            sporButton.titleLabel.font = [UIFont systemFontOfSize:15];
            sporButton.backgroundColor = [UIColor whiteColor];
            [sporButton setTitle:sporStr forState:UIControlStateNormal];
            [sporButton setTitleColor:MainColor forState:UIControlStateNormal];
            [sporButton addTarget:self action:@selector(moresporinfo) forControlEvents:UIControlEventTouchUpInside];
            return sporButton;
        }else{
            return footer;
        }
    }else{
        if (datadictionary.hotComments.count>=10) {
            NSString *commentStr = [NSString stringWithFormat:@"查看更多评论(%@)>",datadictionary.commentCount];
            UIButton *commentButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64)];
            commentButton.titleLabel.font = [UIFont systemFontOfSize:15];
            commentButton.backgroundColor = [UIColor whiteColor];
            [commentButton setTitle:commentStr forState:UIControlStateNormal];
            [commentButton setTitleColor:MainColor forState:UIControlStateNormal];
            [commentButton addTarget:self action:@selector(morecommentInfo) forControlEvents:UIControlEventTouchUpInside];
            return commentButton;
        }else if(datadictionary.hotComments.count==0){
            footer.backgroundColor = [UIColor whiteColor];
            UILabel *fnocomment = [[UILabel alloc]init];
            [footer addSubview:fnocomment];
            [fnocomment makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(footer.centerY).with.offset(0);
                make.centerX.equalTo(footer.centerX).with.offset(0);
                make.height.mas_equalTo(21);
                make.width.mas_equalTo (SCREEN_WIDTH);
            }];
            
            fnocomment.textColor = [UIColor colorWithHexString:@"#8a8a8a"];
            fnocomment.font = [UIFont systemFontOfSize:15];
            fnocomment.text = @"暂无评论,我来说两句";
            fnocomment.textAlignment = NSTextAlignmentCenter;
            return footer;
        }else{
            return footer;
        }
    }
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)])
    {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
    {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==0) {
        return 0.0001;
    }else{
        return 10;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section<1) {
        return 0.0001;
    }else  if(section==1){
        if (datadictionary.hotSponsors.count>=10) {
            return 64;
        }else{
            return 0.0001;
        }
    }else{
        if (datadictionary.hotComments.count>=10 || datadictionary.hotComments.count==0) {
            return 64;
        }else{
            return 0.0001;
        }
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section==0 &&indexPath.row==3) {
        [self moresporinfo];
    }
    
    if (indexPath.section==0 && indexPath.row ==2) {
        ZCdetectiondetailsVC * detection = [[ZCdetectiondetailsVC alloc]init];
        detection.pid = self.pid;
        detection.test_result = datadictionary.testreportDetail;
        detection.projectModel = datadictionary;
        detection.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:detection animated:YES];
    }

     NSLog(@"indexPath = %@",indexPath);
    if (indexPath.section ==2) {
        if (indexPath.row>0) {
            [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
            [self commentButtonClickindex:indexPath];
        }
    }
    
   
}

-(void)ClickZCInvolvedContentCellButton:(NSIndexPath *)index{
    
    double degree;
    NSString *titleButton = nil;
    if (self.iszhan) {
        self.iszhan = NO;
        degree = 0;
        titleButton = @"展开详情";
    }else{
        self.iszhan = YES;
        degree = M_PI;
        titleButton = @"收起";
    }
    if ([self.stateid isEqualToString:@"0"]) {
        [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:5 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];

    }else{
        [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:4 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
    }
    
    ZCInvolvedContentCell *cell = (ZCInvolvedContentCell*)[self.tableView cellForRowAtIndexPath:index];
    
    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
        
        cell.deatailButton.imageView.layer.transform = CATransform3DMakeRotation(degree, 0, 0, 1);
        [cell.deatailButton setTitle:titleButton forState:UIControlStateNormal];
        CGSize size = CGSizeMake(320,2000); //设置一个行高上限
        NSDictionary *attribute = @{NSFontAttributeName: cell.deatailButton.titleLabel.font};
        CGFloat labelWidth = [cell.deatailButton.titleLabel.text boundingRectWithSize:size options: NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin| NSStringDrawingUsesFontLeading attributes:attribute context:nil].size.width;
        cell.deatailButton.imageEdgeInsets = UIEdgeInsetsMake(0, labelWidth+3, 0, -labelWidth-3);
        cell.deatailButton.titleEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 15);
        

    } completion:NULL];
}


-(CGFloat)tableViewIndexPath:(NSIndexPath *)indexPath{
    
    NSString *reuseIdentifier = @"contentCell";
    ZCInvolvedContentCell *cell = [self.tableView dequeueReusableCellWithIdentifier:  reuseIdentifier];
    
    NSString *information = datadictionary.content;
    CGFloat count = cell.textView.font.lineHeight * 5 +26;
    CGSize size = CGSizeMake(SCREEN_WIDTH-18*2,2000); //设置一个行高上限
    NSDictionary *attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:15]};
    CGFloat height = [information boundingRectWithSize:size options: NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin| NSStringDrawingUsesFontLeading attributes:attribute context:nil].size.height;
    height +=26;
    CGFloat h;
    
    NSLog(@"height = %f , count =%f",height,count);
    if (height<count) {
        if (self.iszhan) {
            NSLog(@"1");
            h = height;
        }else{
            NSLog(@"2");
            h = height >count?(count):height;
        }
        return h;
    }else{
        if (self.iszhan) {
            NSLog(@"3");
            return height+30;
        }else{
            NSLog(@"4");
            return count +30;
        }
    }
}



#pragma mark 点击我想说两句
-(void)ClickCommentButtonconnect{
    if (UserModel.password.length>1) {
        [[HcCustomKeyboard customKeyboard]textViewShowView:self customKeyboardDelegate:self andType:HcCustomKeyboardTypeBtton andplaceholder:@"我来说两句"];
    }else{
        ZCLoginVC *loginVC = [[ZCLoginVC alloc]init];
        loginVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:loginVC animated:YES];
    }
}
#pragma mark textView 内容
-(void)talkBtnClick:(UITextView *)textViewGet
{
    [NetworkManager requestFoundingGetOnecommentWithId:self.pid Mid:UserModel.mid password:UserModel.password content:textViewGet.text pid:@"0" success:^(NSDictionary *dictResponse) {
        NSString *err = [NSString stringWithFormat:@"%@",[dictResponse objectForKey:@"err"]];
        
        NSString *content =[NSString stringWithFormat:@"%@",[dictResponse objectForKey:@"content"]];
        if ([err isEqualToString:@"0"]) {
            [[[iToast makeText:@"评论成功"]setGravity:iToastGravityCenter] show];
            
            ZCInvolvedDetailsModelHotComments *hotcom = [[ZCInvolvedDetailsModelHotComments alloc]init];
            hotcom.avatar = UserModel.avatar;
            hotcom.ctime =[NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]];;
            hotcom.content = textViewGet.text;
            hotcom.likecount = @"0";
            hotcom.commentCount = @"0";
            hotcom.username = UserModel.username;
            hotcom.hotCommentsIdentifier = content;
            hotcom.forId = self.pid;
            hotcom.pid =content;
            hotcom.ctype = @"1";
            [datadictionary.hotComments insertObject:hotcom atIndex:0];
            
            NSLog(@"---------------------------");
            
            [self.tableView reloadData];
        }else{
            [[[iToast makeText:@"评论失败"]setGravity:iToastGravityCenter] show];
        }
    } failure:^(NSError *error) {
    }];
    
    NSLog(@"user.name = %@",UserModel.username);
    
    NSLog(@"%@",textViewGet.text);
}

#pragma mark 评论
-(void)commentButtonClickindex:(NSIndexPath *)indexPath{
    NSLog(@"评论---%ld",indexPath.row);
    ZCCommentDetailsVC *zcmment = [[ZCCommentDetailsVC alloc]init];
    zcmment.comments =(ZCInvolvedDetailsModelHotComments *)datadictionary.hotComments[indexPath.row-1];
    zcmment.pid = self.pid;
    zcmment.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:zcmment animated:YES];
}

#pragma mark 赞
-(void)likeButtonClickindex:(NSIndexPath *)indexPath islogin:(BOOL)login{
    NSLog(@"赞");
     if (login== YES) {
        ZCInvolvedDetailsModelHotComments *model = datadictionary.hotComments[indexPath.row-1];
        [NetworkManager requestFoundingGetOnecommentlikeWithCId:model.hotCommentsIdentifier Mid:UserModel.mid password:UserModel.password success:^(NSDictionary *dictResponse) {
        } failure:^(NSError *error) {
            
        }];
     }else{
         [self login];
     }
}

#pragma mark 更多支持者
-(void)moresporinfo{
    ZCSponsorVC *spon = [[ZCSponsorVC alloc]init];
    spon.strPid = self.pid;
    spon.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:spon animated:YES];
}
#pragma mark 更多评论
-(void)morecommentInfo{
    ZCCommentVC *comment = [[ZCCommentVC alloc]init];
    comment.pid = self.pid;
    comment.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:comment animated:YES];
}

#pragma mark 收藏

-(void)collectionButtonPressed{
    if (UserModel.password.length>1) {
        if (datadictionary.ifcollection==0) { //收藏
            [NetworkManager  requestFoundingGetOnecolletionWithId:self.pid Mid:UserModel.mid password:UserModel.password ifcollection:@"1" success:^(NSDictionary *dictResponse) {
                datadictionary.ifcollection = 1;
                [[iToastImage makeinit]showImg:[UIImage imageNamed:@"projectdetail_collection_success"]];
                [self.toolView.collectBtn setImage:[UIImage imageNamed:@"involve_tool_xing_yes"] forState:UIControlStateNormal];
                } failure:^(NSError *error) {
                
            }];
        }else{
            NSLog(@"取消");
             //取消收藏
            [NetworkManager  requestFoundingGetOnecolletionWithId:self.pid Mid:UserModel.mid password:UserModel.password ifcollection:@"0" success:^(NSDictionary *dictResponse) {
                datadictionary.ifcollection = 0;
                [[iToastImage makeinit]showImg:[UIImage imageNamed:@"projectdetail_collection_fail"]];
//                if ([[dictResponse objectForKey:@"err"] isKindOfClass:[NSString class]]) {
//                    NSString *str = (NSString *)[dictResponse objectForKey:@"err"];
//                    if ([str isEqualToString:@"0"]) {
                        [self.toolView.collectBtn setImage:[UIImage imageNamed:@"involve_tool_xing_no"] forState:UIControlStateNormal];
//                    }
//                }
                
            } failure:^(NSError *error) {
                
            }];
        }
    }else{
        [self login];
    }
}
    
    
#pragma mark 底部分享
-(void)shareButtonPressed{
    ActionView *action = [[ActionView alloc]initWithFrame:CGRectZero];
    action.pid = self.pid;
    [action showInView:self.view];
}

#pragma mark 立即支持
-(void)submitButtonClick{
    NSLog(@"立即支持");
    if (UserModel.password.length>1) {
        if (![datadictionary.result isEqualToString:@"0"] || ([datadictionary.result isEqualToString:@"0"] &&[datadictionary.state isEqualToString:@"2"])) {
            ZCRaiseVC *raise = [[ZCRaiseVC alloc]init];
            raise.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:raise animated:YES];
        }else{
            ZCRaisePayVC *payvc = [[ZCRaisePayVC alloc]init];
            payvc.markStr = @"2";
            payvc.pid = self.pid;
            payvc.pjname = datadictionary.pjname;
            payvc.pjusername = datadictionary.username;
            [self.navigationController pushViewController:payvc animated:YES];
        }
    }else{
        [self login];
    }
}

-(void)login{
    ZCLoginVC *loginVC = [[ZCLoginVC alloc]init];
    loginVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:loginVC animated:YES];
}
#pragma mark 显示分享
-(void)showShareView{
    NSLog(@"分享---");
    CGFloat xWidth = SCREEN_WIDTH - 60.0f;
    CGFloat yHeight = xWidth+30;
    payShareView *poplistview = [[payShareView alloc] initWithFrame:CGRectMake(0,0, xWidth, yHeight) andpid:self.pid];
    poplistview.ButtonClik = ^(NSInteger index){
        ZCMeRaiseVC * zcmeaise = [[ZCMeRaiseVC alloc]init];
        zcmeaise.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:zcmeaise animated:YES];
    };
    [poplistview show];
}


//显示图片浏览器
-(void)showPhotoBrowser:(NSInteger)index{
    WyzAlbumViewController *wyzAlbumVC = [[WyzAlbumViewController alloc]init];
    wyzAlbumVC.imgArr = self.imagesURL;
    NSLog(@"imgArr = %@",self.imagesURL);
    [self.navigationController pushViewController:wyzAlbumVC animated:YES];
}

//请求健康豆
-(void)gotodeans{
    [NetworkManager requestIndexGetSharefinishWithmid:UserModel.mid password:UserModel.password newsid:self.pid success:^(NSDictionary *dictResponse) {
        
    } failure:^(NSError *error) {
        
    }];
}

-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}


@end
